<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 交易单
 */
class Order extends Model
{
    protected $table = 'orders';

    protected $fillable = [
        'id',
        'eid', //委托单id
        'uid', //用户id
        'cid', //币种id
        'sid',
        'number_no', //成交编号
        'order_no', //订单编号
        'num', //数量
        'price', //成交价
        'type', //类型 5交易买入 6交易卖出
        'proc', //手续费
        'real_price', //实际价
        'total_price', //总价格
        'created_at',
        'updated_at'
    ];
    const TYPE_ONE = 1;
    const TYPE_TWO = 2;
    public static $TYPE = [
        self::TYPE_ONE => '买入',
        self::TYPE_TWO => '卖出',
    ];

    //关联user表
    public function users()
    {
        return $this->hasOne('App\\Models\\User', 'id', 'uid');
    }

    public function users_sid()
    {
        return $this->hasOne('App\\Models\\User', 'id', 'sid');
    }
    public function currency()
    {
        return $this->hasOne('App\\Models\\Currency', 'id', 'cid');
    }
}
